﻿var Domain=window.location.host.substring(window.location.host.indexOf(".")+1);
//广告轮播
function adpicstart(p){
    if ($(".slide-pic").length > 0) {
        var defaultOpts = { interval: 2500, fadeInTime: 300, fadeOutTime: 200 };
        var _titles = $("."+p+" ul.slide-txt li");
        var _titles_bg = $("."+p+" ul.op li");
        var _bodies = $("."+p+" ul.slide-pic li");
        var _count = _titles.length;
        var _current = 0;
        var _intervalID = null;
        var stop = function () { window.clearInterval(_intervalID); };
        var slide = function (opts) {
            if (opts) {
                _current = opts.current || 0;
            } else {
                _current = (_current >= (_count - 1)) ? 0 : (++_current);
            };
            _bodies.filter(":visible").fadeOut(defaultOpts.fadeOutTime, function () {
                _bodies.eq(_current).fadeIn(defaultOpts.fadeInTime);
                _bodies.removeClass("cur").eq(_current).addClass("cur");
            });
            _titles.removeClass("cur").eq(_current).addClass("cur");
            _titles_bg.removeClass("cur").eq(_current).addClass("cur");
        };
        var go = function () {
            stop();
            _intervalID = window.setInterval(function () { slide(); }, defaultOpts.interval);
        };
        var itemMouseOver = function (target, items) {
            stop();
            var i = $.inArray(target, items);
            slide({ current: i });
        };
        _titles.hover(function () { if ($(this).attr('class') != 'cur') { itemMouseOver(this, _titles); } else { stop(); } }, go);
        _bodies.hover(stop, go);
        go();
    }
}
function escape2(str){
    return escape(str).replace(/\+/g,"%2b");
}
//search_form开始
var input="";
function setInput(){
    var hid=document.getElementById("hid").value;
    if(document.getElementById("val").value==input)
        document.getElementById("val").value="";
    if(hid=="1"||hid=="2"){
        input="请输入电子元器件型号...";
    }
    else if(hid=="3"){
        input="请输入商情资讯关键词...";
    }
    if(document.getElementById("val").value=="")
        document.getElementById("val").value=input;
}
function startSj(){
    var txt=document.getElementById("val");
    var btn_qc=document.getElementById("icon_qc");
    if(txt.value==""){txt.value=input;}
    btn_qc.onclick=function(){
        txt.value="";
        document.getElementById("icon_qc").style.display="none";
    }
    txt.onkeyup=function(){
        if(txt.value!=""&&txt.value!=input){ document.getElementById("icon_qc").style.display="block";}
        else{document.getElementById("icon_qc").style.display="none";}
    }
    txt.onfocus=function(){
        document.getElementById("s_border").style.border="1px solid #FF9900";
        document.getElementById("val").style.fontWeight="bold";
        if(txt.value==input){
            txt.value="";
        }
    }
    txt.onblur=function(){
        document.getElementById("s_border").style.border="1px solid #ccc";
        if(txt.value==""||txt.value==input){
            document.getElementById("val").style.fontWeight="normal";
        }
        if(txt.value==""){
            txt.value=input;
        }
    }
}
startSj();
function settab(id){
    var obj = document.getElementById("search_tabs").getElementsByTagName("div");
    for (j = 0; j < obj.length; j++) {
        if(obj[j].id==id){
            document.getElementById("hid").value=id;
            obj[j].className = "inTabs";
            if(id==1) {
                document.getElementById("jq").style.display="block";
                document.getElementById("val").style.width="300px";
                document.getElementById("icon_qc").style.right="62px";
                document.getElementById("selectbox").style.display="none"
            }
            else {
                document.getElementById("jq").style.display="none";
            }
            if(id==2) {
                document.getElementById("selectbox").style.display="block";
                document.getElementById("val").style.width="275px";
                document.getElementById("icon_qc").style.right="95px";
            }
            if(id==3) {
                document.getElementById("selectbox").style.display="none"
                document.getElementById("val").style.width="385px";
                document.getElementById("icon_qc").style.right="3px";
            };
        }
        else{
            obj[j].className = "";
        }
    }
    setInput();
}
settab(document.getElementById("hid").value);
function search_form(){
    var addr=document.getElementById("hid").value;
    var val=document.getElementById("val").value;
    if(val==input){
        val="";
    }
    if (addr=="1"&&Strlength(val)<2){
        alert("请输入2位以上型号查询");
        return false;
    }
    else{
        val=escape2(val);
        var isjq="";
        if(document.getElementById("exactprefix").checked){
            isjq="&exactprefix=1";}
        if(addr=="2"){
            addr=document.getElementById("selecttbg").value;
        }

        switch(addr){
            case "1":window.open('http://www.'+Domain+'/stock/search.asp?key='+val+isjq,'_self'); break;
            case "3":window.open('http://www.'+Domain+'/search/info.asp?key='+val,'_self'); break;
            case "51":window.open('http://www.'+Domain+'/search/brand.asp?key='+val,'_self'); break;
            case "52":window.open('http://www.'+Domain+'/search/dictionary.asp?key='+val,'_self'); break;
            case "54":window.open('http://www.'+Domain+'/search/icth.asp?key='+val,'_self'); break;
            case "55":window.open('http://www.'+Domain+'/search/transistor.asp?key='+val,'_self'); break;
            case "57":window.open('http://www.'+Domain+'/search/circuit.asp?key='+val,'_self'); break;
            default:if(val!="")val=val+".html";window.open('http://www.114ic.cn/pdf/'+val,'_blank'); break;
        }
    }
    return false;
}
//search_form结束
//中英文长度
function Strlength(s)
{
    var l = 0;
    var a = s.split("");
    for (var i=0;i<a.length;i++) {
        if (a[i].charCodeAt(0)<299) {
            l++;
        }
        else {
            l+=2;
        }
    }
    return l;
}
function getCookie(c_name)
{
    if(document.cookie.length>0){
        c_start=document.cookie.indexOf(c_name + "=")
        if(c_start!=-1){
            c_start=c_start + c_name.length+1
            c_end=document.cookie.indexOf(";",c_start)
            if(c_end==-1) c_end=document.cookie.length
            return unescape(document.cookie.substring(c_start,c_end))
        }
    }
    return ""
}

function DecodeCookie(str) {
    var reval="";
    var strls=str.split("a");
    var a=strls.length-1;
    if(strls.length>0){
        for (var i=strls.length-1;i>=0;i--){
            reval+=String.fromCharCode(eval(strls[i]));
        }
    }
    return reval;
}
//读取会员状态cookie
var userCookie=getCookie("userstr");
if(userCookie.indexOf(",")>=0)
{
    var str=userCookie.split(",");
    var cname=DecodeCookie(str[2]);
    var usertype=str[3];
    var box_con_loginhtml="<p class='logined_p'>企业:"+cname+"</p><p class='logined_p'>状态:"+fusertype(usertype)+"</p><p class='logined_p'><a href='http://member."+Domain+"/member/'>会员首页</a> <a href='http://member."+Domain+"/inc/exit.asp'>退出系统</a></p>";
    var top_lhtml="<span>您好"+str[1]+",欢迎来到114ic网!</span><a href='http://member."+Domain+"/member/'>会员首页</a><a href='http://member."+Domain+"/inc/exit.asp'>退出系统</a><a class='b-r-s-r' href=\"javascript:window.external.AddFavorite('http://www.114ic.com', '114IC电子网--找IC,尽在114IC!')\">加为收藏</a>";
    $(".box_con_login").html(box_con_loginhtml);
    $(".top_l").html(top_lhtml);

    if($(".plxj_login").length>0){
        $(".plxj_login_l").hide();
        $(".plxj_login_r").hide();
        $("#code").val("code");
        if($(".plxj_yzm").length>0){
            $(".plxj_yzm").hide();
        }
        if($(".code").length>0){
            $(".code").hide();
        }
        $("[name='Submit3']").show();
    }
}
else{
    if($(".plxj_login").length>0){
        $(".plxj_login_l").show();
        $(".plxj_login_r").show();
        if($(".plxj_yzm").length>0){
            $(".plxj_yzm").show();
        }
        if($(".code").length>0){
            $(".code").show();
        }
        $("[name='Submit3']").hide();
    }
}
//会员等级
function fusertype(obj){
    var str="";
    switch(obj){
        case "1":str="采购商";break;
        case "2":str="普通";break;
        case "3":str="特惠";break;
        case "4":str="四星";break;
        case "5":str="五星";break;
        case "6":str="高级";break;
        case "7":str="VIP";break;
    }
    return str;
}
//导航条
var navls=document.getElementById("nav").getElementsByTagName("a");
var submenu=document.getElementById("smallnav").getElementsByTagName("div");
for(var i=0;i<navls.length-1;i++){
    if(navls[i].parentElement.id=="tbg"){
        submenu[i].style.display="block";
        var als=submenu[i].getElementsByTagName("a");
        for(var n=0;n<als.length;n++){
            if(document.getElementById("tbg2").value==n+1){
                als[n].id="tbg2";
            }
        }
    }
    else{
        submenu[i].style.display="none";
    }
    navls[i].onmouseover=function(){
        fid=this.id.substring(6,7);
        for(var j=0;j<submenu.length;j++){
            if(fid==j){
                submenu[j].style.display="block";
            }
            else{
                submenu[j].style.display="none";
            }
        }
    }
}
//首页会员登陆
function recheck()
{
    if (document.loginForm.uname.value =="")
    {
        alert("请填写您的用户名！");
        document.loginForm.uname.focus();
        return false;
    }
    if (loginForm.pwd.value=="")
    {
        alert("请输入密码！");
        loginForm.pwd.focus();
        return false;
    }
}
//首页滚动
function gundong(obj,h,s,t){
    //obj对象id
    //h滚动高度
    //s滚动速度
    //停留时间
    var box=document.getElementById(obj),can=true;
    box.innerHTML+=box.innerHTML;
    box.onmouseover=function(){can=false};
    box.onmouseout=function(){can=true};
    new function (){
        var stop=box.scrollTop%h==0&&!can;
        if(!stop)box.scrollTop==parseInt(box.scrollHeight/2)?box.scrollTop=0:box.scrollTop++;
        setTimeout(arguments.callee,box.scrollTop%h?s:t);
    };
}
//product
function vpropicshow(obj){
    var showimg=document.getElementById("showimg");
    var img=obj.firstChild;
    var li=obj.parentNode;
    var lils=document.getElementById("vpropic_s").getElementsByTagName("li");
    for(var i=0;i<lils.length;i++){
        lils[i].style.border="1px solid #ccc";
    }
    li.style.border="1px solid #FF6600";
    showimg.src=img.src;
}


//导航条
function selNavType() {
    document.getElementById("selectbox").className = "selectbox1";
    var obj1 = document.getElementById("searchbox");
    var obj2 = obj1.getElementsByTagName("div");

    for (var i = 0; i < obj2.length; i++) {
        obj2[i].onmouseover = function () {
            this.style.background = "#ccc";
        }
        obj2[i].onmouseout = function () {
            this.style.background = "#fff";
        }
        obj2[i].onclick = function () {
            document.getElementById("selectbox").innerHTML = this.innerHTML;
            document.getElementById("selecttbg").value = this.id.substring(4);
            document.getElementById("selectbox").className = "selectbox";
            obj1.style.display = 'none';
        }
    }
    obj1.style.display = 'block';
}
function setShowType() {
    var selecttbg =  document.getElementById("selecttbg").value;
    var div = document.getElementById("searchbox").getElementsByTagName("div");
    for (var i = 0; i < div.length; i++) {
        if (div[i].id.substring(4, 6) == selecttbg) {
            document.getElementById("selectbox").innerHTML = div[i].innerHTML;
        }
    }
    $("#searchbox").bind("mouseleave",function(){document.getElementById("searchbox").style.display='none';});
}
setShowType();


//微信公众号
function weixin(){
    var div;
    var img;
    var input1;
    var input2;
    try {
        div = document.createElement("<div class='weixin'></div>");
        img = document.createElement("<img src='http://img.114ic.com/img/weixin7575.jpg'/>");
        input1 = document.createElement("<input value='微信扫一扫' type='text' readonly='readonly'/>");
        input2 = document.createElement("<input value='商机真不少' type='text'' readonly='readonly'/>");
    } catch (e) {
        div = document.createElement("div");
        div.setAttribute("class", "weixin");
        img = document.createElement("img");
        img.setAttribute("src", "http://img.114ic.com/img/weixin7575.jpg");
        input1 = document.createElement("input");
        input1.type="text";
        input1.value="微信扫一扫";
        input1.readOnly="readonly";
        input2 = document.createElement("input");
        input2.type="text";
        input2.value="商机真不少";
        input2.readOnly="readonly";
    }
    div.appendChild(img);
    div.appendChild(input1);
    div.appendChild(input2);
    document.body.appendChild(div);
}
(function(){
    var href=location.href.toLowerCase();
    href=href.replace("http://","");
    href=href.replace("/","");
    if(href=="www."+Domain.toLowerCase()){
        weixin();
    }
})();
//百度推送
(function(){
    if(!document.getElementById("pagestatus")){
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        }
        else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    }
})();
//360推送
(function(){
    var src = (document.location.protocol == "http:") ? "http://js.passport.qihucdn.com/11.0.1.js?c7f0ac80266cb70ca7e1d1a2c06a7927":"https://jspassport.ssl.qhimg.com/11.0.1.js?c7f0ac80266cb70ca7e1d1a2c06a7927";
    document.write('<script src="' + src + '" id="sozz"><\/script>');
})();
//QQ快速登录
function qqlogin() {
    var reurl = "http://member.114ic.com/MemberNet/loginother/qqbind.aspx";
    if (location.href.indexOf("?reurl=") > 0) {
        reurl += location.href.substring(location.href.indexOf("?reurl="));
    }
    window.open("https://graph.qq.com/oauth/show?which=ConfirmPage&display=pc&client_id=101331335&response_type=token&scope=all&redirect_uri=" + encodeURIComponent(reurl), "_self");
}
//顶部放假通知
/*
$(document).ready(function(){
	if(location.href=="http://www."+Domain+"/"){
		var strHtml='<div style=" width:100%; height:30px; line-height:30px; background:#FFF9D9;">';
		strHtml+='<p style="width:1200px; margin:0 auto; color:#FF6D00; text-align:center;font-size:13px">';
		strHtml+='尊敬的用户，春节放假时间:2月9日至2月22日，网站暂停人工服务，不便之处敬请谅解！公司全体员工恭祝各位春节快乐、身体健康、万事如意、财源广进！';
		strHtml+='</p>';
		$("body").prepend(strHtml);
	}
});
*/